package com.bbva.kyfb.kyfbwsfo.services.ejecucion;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.bbva.jee.arq.spring.core.gce.ExcepcionEjecucionAplicacion;
import com.bbva.jee.arq.spring.core.httpService.HttpService;
import com.bbva.jee.arq.spring.core.log.I18nLog;
import com.bbva.jee.arq.spring.core.log.I18nLogFactory;
import com.bbva.kyfb.kyfbdto.firmas.bo.InfoAssistantDto;
import com.bbva.kyfb.kyfbdtofo.FicheroRequest;
import com.bbva.kyfb.kyfbdtofo.ResponseDto;
import com.bbva.kyfb.kyfbdtofo.fachada.interfaces.v01.ExecuteServiceV01;
import com.bbva.kyfb.kyfbofo.interfaces.ExecuteFileBO;
import com.bbva.kyfb.kyfbofo.interfaces.ExecuteTransactionBO;
import com.bbva.kyfb.kyfbutils.constantes.ConstantesFO;

@Service
@HttpService(serviceName = "servicioEjecucionHttp")
public class ExecuteServiceRestV01 implements ExecuteServiceV01 {
	
	/** Variable LOG. */
	private static final I18nLog log = I18nLogFactory.getLogI18n(ExecuteServiceRestV01.class);

	@Autowired
	private ExecuteFileBO executeFileBO;

	@Autowired
	@Qualifier("transferenciaBO")
	private ExecuteTransactionBO executeTransactionBO;
	
	/**
	 	Url: http://localhost:8080/kyfb_mult_web_kyfbws_03/services/rest/v01/service/execution/file/
	 
		<ficheroRequest>
		<bancoInterno>0001</bancoInterno>
		<canal>0023</canal>
		<idOrden>hlgghic7</idOrden>
		<numItem>468898710394</numItem>
		<referencia>20027999</referencia>
		<subproducto>1</subproducto>
		<tipoFirma>FS</tipoFirma>
		<tipoOrden>TRA</tipoOrden>
		<aplicacion>tlsb</aplicacion>
		</ficheroRequest>
	 */
	@Override
	public InfoAssistantDto executeFile(FicheroRequest aFicheroRequest) {
		ResponseDto responseDto = new ResponseDto();
		
		try {
			log.info("******************Ingresando al Servicio******************");
			log.info(aFicheroRequest.toString());
			responseDto = executeFileBO.execute(aFicheroRequest);
		}
		catch(Exception exception) {
			log.error("******************Error en Servicio******************");
			log.error(exception.getMessage());
			responseDto.setAssistantCodError(ConstantesFO.COD_ERROR);
			responseDto.setAssistantDescError(exception.getMessage());
		}
		
		return responseDto.getInfoAssistantDto();
	}
	
	/**
		URL: http://localhost:8080/kyfb_mult_web_kyfbws_03/services/rest/v01/service/execution/transfer
		 
		<ficheroRequest>
		<bancoInterno>0001</bancoInterno>
		<canal>0023</canal>
		<idOrden>h7lmczot</idOrden>
		<numItem>438735613826</numItem>
		<referencia>20027999</referencia>
		<tipoOrden>TRF</tipoOrden>
		<aplicacion />
		<bancoProducto>0001</bancoProducto>
		<producto>1380</producto>
		<subproducto>0</subproducto>
		<tipoFirma>FS</tipoFirma>
		</ficheroRequest>
	 */
	@Override
	public InfoAssistantDto executeTransfer(FicheroRequest aFicheroRequest) {
		ResponseDto responseDto = new ResponseDto();
		
		try {
			responseDto = executeTransactionBO.execute(aFicheroRequest);
		}
		catch(Exception e) {
		}
		
		return responseDto.getInfoAssistantDto();
	}
}